package com.kara.webapp.services;

import org.apache.tapestry5.ioc.Configuration;
import org.apache.tapestry5.ioc.services.Coercion;
import org.apache.tapestry5.ioc.services.CoercionTuple;
import org.appfuse.model.LabelValue;


public class TypeCoercions {
  
  public static void contributeCoercions(Configuration<CoercionTuple> configuration) {
    Coercion<String, LabelValue> stringToLabelValue = new Coercion<String, LabelValue>() {

      public LabelValue coerce(String input) {
        return new LabelValue("",input);
      }
    };
    Coercion<LabelValue, String> lebelValueToString = new Coercion<LabelValue, String>() {

      public String coerce(LabelValue input) {
        if (input == null) {
          return "-1";
        }
        return input.getValue();
      }
    };
    configuration.add(new CoercionTuple<String, LabelValue>(String.class, LabelValue.class, stringToLabelValue));
    configuration.add(new CoercionTuple<LabelValue, String>(LabelValue.class, String.class, lebelValueToString));
  }
}
